#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	string x, str;
	int n, opt;
	cin >> n >> str;
	while (n--)
	{
		cin >> opt;
		if (opt == 1)
		{
			cin >> x;
			str += x;//str=str.append(x);
			cout << str << endl;
		}
		else if (opt == 2)
		{
			int a, b;
			cin >> a >> b;
			str = str.substr(a, b);
			cout << str << endl;
		}
		else if (opt == 3)
		{
			int m;
			cin >> m >> x;
			str = str.insert(m, x);
			cout << str << endl;
		}
		else
		{
			cin >> x;
			cout << (int)str.find(x) << endl;
		}
	}
	return 0;
}
